package com.jt.controller;

import com.jt.annotation.RequiredLog;
import com.jt.pojo.Repertory;
import com.jt.service.RepertoryService;
import com.jt.vo.PageResult;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/itemck")
@CrossOrigin
public class RepertoryController {
    @Autowired
    private RepertoryService repertoryService;
    @GetMapping("/getItemckList")
//    @RequiredLog
    public SysResult getItemckList(PageResult pageResult){
        pageResult= repertoryService.getItemckList(pageResult);
        return SysResult.success(pageResult);
    }

    @PutMapping("/updateItemckStatus")
    @RequiredLog
    public SysResult updateStatus(@RequestBody Repertory repertory){
        repertoryService.updateStatus(repertory);
        System.out.println(Arrays.asList(repertory));
        return SysResult.success();
    }

    @DeleteMapping("/deleteItemckById")
    @RequiredLog
    public SysResult deleteItemckById(Integer id){
        repertoryService.deleteItemckById(id);
        return SysResult.success();
    }
    /**根据ID查询数据库
     */
    @GetMapping("/{id}")
    @RequiredLog
    public SysResult getItemckById(@PathVariable Integer id){
        Repertory repertory =  repertoryService.getItemckById(id);
        return SysResult.success(repertory);
    }
    @PutMapping("/updateItemck")
    @RequiredLog
    public SysResult updateItemck(@RequestBody Repertory repertory){
        System.out.println(repertory);
        repertoryService.updateItemck(repertory);
        System.out.println(repertory);
        return SysResult.success(repertory);
    }
    @PostMapping("/additemck")
    public SysResult addItemck(@RequestBody Repertory repertory){
        repertoryService.additemck(repertory);
        return SysResult.success();
    }

}
